package dbsucxentW.statisticsW;

/**
 * Created on 28 May 2008
 * @author: Klarinda
 * Objective: Class to store the statistics of the data (PathCount, TotalPathCount, ValueSelectivity)
 * Please refer to Sandeep's Prefetching paper for definition of each term 
 */

import java.util.Vector;

public class XMLDataStatistics {

	private static final int 	INITVECTORCAPACITY = 50;
	private Vector<Integer> 	_PathId;			//PathId			
	private Vector<String> 		_Path;				//Path
	private Vector<Integer> 	_PathCount;			//C(P)
	private int	   				_TotalPathCount;	//T = sigma C(Pj) 
	private Vector<Integer> 	_ValueSelectivity;	//V(P)
	
	public XMLDataStatistics() {
		_PathId = new Vector<Integer>(INITVECTORCAPACITY);
		_Path = new Vector<String>(INITVECTORCAPACITY);
		
		_PathCount = new Vector<Integer>(INITVECTORCAPACITY);
		_TotalPathCount = 0;
		_ValueSelectivity = new Vector<Integer>(INITVECTORCAPACITY);
	}
	
	public void add(int PathId, String Path, int PathCount, int ValueSelectivity) {
		_PathId.add(new Integer(PathId));			
		_Path.add(Path);
		
		_PathCount.add(new Integer(PathCount));		
		_ValueSelectivity.add(new Integer(ValueSelectivity));
	}
	public void setTotalPathCount(int tot) {
		_TotalPathCount = tot;
	}
	
	public int getPathIdAt(int index) {
		return _PathId.get(index).intValue();
	}
	public String getPathAt(int index) {
		return _Path.get(index);
	}
	public int getPathCountAt(int index) {
		return _PathCount.get(index).intValue();
	}
	public int getValueSelectivityAt(int index) {
		return _ValueSelectivity.get(index).intValue();
	}
	
	public int getTotalPathCount() {
		return _TotalPathCount;
	}
	

	/** get the PathID given the Path  */
	public int getPathId(String path) {
		int index = _Path.indexOf(path);
		return getPathIdAt(index);
	}
	/** get the PathCount given the Path  */
	public int getPathCount(String path) {
		int index = _Path.indexOf(path);
		return getPathCountAt(index);
	}
	/** get the ValueSelectivity given the PathID  */
	public int getValueSelectivity(String path) {
		int index = _Path.indexOf(path);
		return getValueSelectivityAt(index);
	}

	/** get the Path given the PathID  */
	public String getPath(int pathid) {
		int index = _PathId.indexOf(new Integer(pathid));
		return getPathAt(index);
	}
	/** get the PathCount given the PathID  */
	public int getPathCount(int pathid) {
		int index = _PathId.indexOf(new Integer(pathid));
		return getPathCountAt(index);
	}
	/** get the ValueSelectivity given the PathID  */
	public int getValueSelectivity(int pathid) {
		int index = _PathId.indexOf(new Integer(pathid));
		return getValueSelectivityAt(index);
	}

	public int indexOfPathId(int pathid) {
		return _PathId.indexOf(new Integer(pathid));
	}
	public int indexOfPath(String path) {
		return _Path.indexOf(path);
	}

	
	public int size() {
		return _PathCount.size();
	}
	
	public String toString() {
		String str = "PathId \tPath \tPathCount \tValueSelectivity\n";
		for (int i = 0; i < size(); i++) {
			str += 	getPathIdAt(i)+"\t"+getPathAt(i)+"\t"+
					getPathCountAt(i)+"\t"+getValueSelectivityAt(i)+"\n";
		}
		str += "TotalPathCount: "+getTotalPathCount()+"\n";
		return str;
	}
}
